//package com.fs.core.security.util;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//@Component("cookieFilter")
//public class CookieFilter implements Filter {
//
//    private final Logger logger = LoggerFactory.getLogger(getClass());
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        logger.info("===cookie filter init...");
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest req = (HttpServletRequest) servletRequest;
//        HttpServletResponse resp = (HttpServletResponse) servletResponse;
//        Cookie[] cookies = req.getCookies();
//        logger.info("cookie filter start");
//        if (cookies != null) {
//            Cookie cookie = cookies[0];
//            if (cookie != null) {
//                String value = cookie.getValue();
//                StringBuilder builder = new StringBuilder();
//                builder.append("JSESSIONID=" + value + "; ");
//                builder.append("path=/;");
//                builder.append("Secure; ");//HTTPS协议下应启用Secure属性
//                builder.append("HttpOnly; ");//将Cookie设置为HttpOnly，防止被脚本获取
//                resp.setHeader("Set-Cookie", builder.toString());
//            }
//        }
//        logger.info("cookie filter end...");
//        filterChain.doFilter(servletRequest, resp);
//    }
//
//    @Override
//    public void destroy() {
//        logger.info("===cookie filter complete...");
//    }
//}